package com.example.function.sys.model.pojo;


import com.example.common.support.ApplicationContextProvider;
import com.example.function.sys.model.one.SysSupplier;
import com.example.function.sys.model.one.SysSupplierType;
import com.example.function.sys.service.ISysSupplierService;
import com.example.function.sys.service.ISysSupplierTypeService;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;

/**
 * Description: <SysSupplierPojo vo>. <br>
 * <p>
 * generate time:2021-7-22 11:07:56
 *
 * @author hanqf
 * @version V1.0
 */
@Data
public class SysSupplierPojo implements Serializable {
    private static final long serialVersionUID = 1L;

    /*
     * 供应商id
     */
    private Long id;


    /*
     * 登录用户id
     */
    private Long userId;


    /*
     * 供应商代码，00001，00002
     */
    private String supplierCode;


    /*
     * 供应商类型
     */
    private SysSupplierTypePojo supplierType;


    /*
     * 固定电话
     */
    private String supplierCall;


    /*
     * 联系人
     */
    private String supplierContacts;


    /*
     * 上级供应商id
     */
    private Long supplierParentId;


    /**
     * 实体对象复制到数据对象
     */
    public static SysSupplierPojo wrapper(SysSupplier sysSupplier) {
        SysSupplierPojo sysSupplierPojo = new SysSupplierPojo();
        BeanUtils.copyProperties(sysSupplier, sysSupplierPojo);
        sysSupplierPojo.setUserId(sysSupplier.getUserIdFk());

        final ISysSupplierService sysSupplierService = (ISysSupplierService) ApplicationContextProvider.getBean("sysSupplierService");

        final ISysSupplierTypeService sysSupplierTypeService = (ISysSupplierTypeService) ApplicationContextProvider.getBean("sysSupplierTypeService");
        final SysSupplierType supplierType = sysSupplierTypeService.findById(sysSupplier.getSupplierTypeFk());
        sysSupplierPojo.setSupplierType(SysSupplierTypePojo.wrapper(supplierType));
        return sysSupplierPojo;
    }

}



